home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3883 / 3883.xpi / chrome / tempomail.jar / content / manage.js < prev    next >
Text File  |  2006-12-08  |  3KB  |  87 lines

  1.  var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  2.  
  3.  
  4. function tempomail_getpref(pref){
  5.     
  6.     var prefResult;
  7.         try{
  8.                 prefResult = prefs.getCharPref(pref);
  9.         }
  10.         catch(e){
  11.                 prefs.setCharPref(pref, prefDefaultVal);
  12.                 prefResult = prefDefaultVal;
  13.         }
  14.         return prefResult;
  15. }
  16.  
  17. function tempomail_options(){
  18.     tempomail_write("test");
  19.     window.openWindow(prefwindow,"chrome://tempomail/content/options.xul","","");
  20. }
  21.  
  22. function tempomail_load(){
  23.  
  24.     var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  25.  
  26.     var field = document.getElementById('tempomail-realname');
  27.     var prefmail = tempomail_getpref('extensions.tempomail.drn');
  28.     field.value = prefmail;
  29. }
  30.  
  31. function tempomail_create(){
  32.  
  33.     var realname = document.getElementById('tempomail-realname').value;
  34.     var duree = document.getElementById('tempomail-expire').value;
  35.     var error = document.getElementById('tempomail-error');
  36.     var bdl = document.getElementById('tempomail-bdl');
  37.     error.value = '';
  38.  
  39.     if(realname.length>0 && tempomail_control(realname)){
  40.         var objHTTP;
  41.         objHTTP = new XMLHttpRequest();
  42.         objHTTP.open("POST",'http://www.tempomail.fr/creation.pl',false);
  43.         objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  44.         objHTTP.send('nomreel='+realname+'&duree='+duree+'&ext=yes');
  45.         var result=objHTTP.responseText;
  46.         
  47.         if(result == parseInt(result)){ // si trop d'alias...
  48.             if(result == "1"){
  49.                 error.value = bdl.getString('extensions.tempomail.error.2');
  50.                             tempomail_write(bdl-fake.getString('extensions.tempomail.error.2'));
  51.             }
  52.             else
  53.             {
  54.                 error.value = bdl.getString('extensions.tempomail.error.1');
  55.                 tempomail_write(bdl-fake.getString('extensions.tempomail.error.1'));
  56.             }
  57.         }
  58.         else{
  59.             tempomail_write(result);
  60.         }
  61.     }
  62.     else
  63.     {
  64.         error.value = bdl.getString('extensions.tempomail.error.2');
  65.         tempomail_write(bdl-fake.getString('extensions.tempomail.error.2'));
  66.     }
  67. }
  68.  
  69. function tempomail_write(mail){
  70.     var elt = window.arguments[0];
  71.     if(elt.type == 'textarea'){
  72.         if(elt.textLength == elt.selectionStart)
  73.             elt.value = elt.value + mail;
  74.         else
  75.             elt.value = elt.value.substring(0, elt.selectionStart) + mail + elt.value.substring(elt.selectionEnd, elt.textLength);
  76.     }
  77.     else{ // input
  78.         elt.value = mail;
  79.     }
  80. }
  81.  
  82. function tempomail_control(mail){
  83.     var ch=/^[^@]+@([^@]+\.[^@]+)$/;
  84.     return (ch.test(mail) && RegExp.$1.toLowerCase()!="tempomail.fr");
  85. }
  86.  
  87.